package cn.edu.cug.cs.gtl.apis.ui.model3duis.projecttree;

import cn.edu.cug.cs.gtl.apis.ui.tree.Tree;
import cn.edu.cug.cs.gtl.apis.ui.tree.TreeNodeData;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;
import java.util.Hashtable;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Vector;

public class ProjectTree extends Tree {

    private JPopupMenu projectNodePopupMenu = new JPopupMenu();
    private JPopupMenu mapNodePopupMenu = new JPopupMenu();
    private JPopupMenu layerNodePopupMenu = new JPopupMenu();

    public ProjectTree() {
        super();
        projectNodePopupMenu = createDefaultPopupMenuForProjectNode();
        mapNodePopupMenu = createDefaultPopupMenuForMapNode();
        layerNodePopupMenu = createDefaultPopupMenuForLayerNode();
    }

    public ProjectTree(Object[] value) {
        super(value);

        projectNodePopupMenu = createDefaultPopupMenuForProjectNode();
        mapNodePopupMenu = createDefaultPopupMenuForMapNode();
        layerNodePopupMenu = createDefaultPopupMenuForLayerNode();
    }

    public ProjectTree(Vector<?> value) {
        super(value);

        projectNodePopupMenu = createDefaultPopupMenuForProjectNode();
        mapNodePopupMenu = createDefaultPopupMenuForMapNode();
        layerNodePopupMenu = createDefaultPopupMenuForLayerNode();
    }

    public ProjectTree(Hashtable<?, ?> value) {
        super(value);

        projectNodePopupMenu = createDefaultPopupMenuForProjectNode();
        mapNodePopupMenu = createDefaultPopupMenuForMapNode();
        layerNodePopupMenu = createDefaultPopupMenuForLayerNode();
    }

    public ProjectTree(TreeNode root) {
        super(root);

        projectNodePopupMenu = createDefaultPopupMenuForProjectNode();
        mapNodePopupMenu = createDefaultPopupMenuForMapNode();
        layerNodePopupMenu = createDefaultPopupMenuForLayerNode();
    }

    public ProjectTree(TreeNode root, boolean asksAllowsChildren) {
        super(root, asksAllowsChildren);

        projectNodePopupMenu = createDefaultPopupMenuForProjectNode();
        mapNodePopupMenu = createDefaultPopupMenuForMapNode();
        layerNodePopupMenu = createDefaultPopupMenuForLayerNode();
    }

    public ProjectTree(TreeModel newModel) {
        super(newModel);

        projectNodePopupMenu = createDefaultPopupMenuForProjectNode();
        mapNodePopupMenu = createDefaultPopupMenuForMapNode();
        layerNodePopupMenu = createDefaultPopupMenuForLayerNode();
    }


    public JPopupMenu getProjectNodePopupMenu() {
        return projectNodePopupMenu;
    }

    public void setProjectNodePopupMenu(JPopupMenu projectNodePopupMenu) {
        this.projectNodePopupMenu = projectNodePopupMenu;
    }

    public JPopupMenu getMapNodePopupMenu() {
        return mapNodePopupMenu;
    }

    public void setMapNodePopupMenu(JPopupMenu mapNodePopupMenu) {
        this.mapNodePopupMenu = mapNodePopupMenu;
    }

    public JPopupMenu getLayerNodePopupMenu() {
        return layerNodePopupMenu;
    }

    public void setLayerNodePopupMenu(JPopupMenu layerNodePopupMenu4) {
        this.layerNodePopupMenu = layerNodePopupMenu4;
    }

    private static DefaultMutableTreeNode add(
            final DefaultMutableTreeNode parent, TreeNodeData userObject,
            final boolean checkable)
    {
        final DefaultMutableTreeNode node = new DefaultMutableTreeNode(userObject);
        parent.add(node);
        return node;
    }


    public static JPopupMenu createDefaultPopupMenuForProjectNode(){

        ResourceBundle resourceBundle=ResourceBundle.getBundle("uiapi_resource", Locale.getDefault());

        JPopupMenu popupMenu = new JPopupMenu();
        JMenuItem menuItem = null;
//        popupmenu.model3duis.project.new_map=New Map...
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.project.new_map"));
        popupMenu.add(menuItem);
//        popupmenu.model3duis.project.add_map=Add Map...
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.project.add_map"));
        popupMenu.add(menuItem);

        popupMenu.addSeparator();
//        popupmenu.model3duis.project.rename=Rename...
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.project.rename"));
        popupMenu.add(menuItem);

        popupMenu.addSeparator();

//        popupmenu.model3duis.project.refresh=Refresh
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.project.refresh"));
        popupMenu.add(menuItem);

        popupMenu.addSeparator();

//        popupmenu.model3duis.project.clear_all=Clear All
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.project.clear_all"));
        popupMenu.add(menuItem);

        popupMenu.addSeparator();

//        popupmenu.model3duis.project.save_as=Save As...
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.project.save_as"));
        popupMenu.add(menuItem);

        popupMenu.addSeparator();

//        popupmenu.model3duis.project.export_geo3dml=export to Geo3DML...
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.project.export_geo3dml"));
        popupMenu.add(menuItem);
//        popupmenu.model3duis.project.export_gvp=export to GVP
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.project.export_gvp"));
        popupMenu.add(menuItem);

        return popupMenu;
    }

    public static JPopupMenu createDefaultPopupMenuForMapNode(){

        ResourceBundle resourceBundle=ResourceBundle.getBundle("uiapi_resource", Locale.getDefault());

        JPopupMenu popupMenu = new JPopupMenu();
        JMenuItem menuItem = null;

//        popupmenu.model3duis.map.new_layer=New Layer
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.map.new_layer"));
        popupMenu.add(menuItem);
//        popupmenu.model3duis.map.add_layer=Add Layer...
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.map.add_layer"));
        popupMenu.add(menuItem);

        popupMenu.addSeparator();

//        popupmenu.model3duis.map.rename=Rename...
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.map.rename"));
        popupMenu.add(menuItem);

        popupMenu.addSeparator();

//        popupmenu.model3duis.map.copy=Copy Map
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.map.copy"));
        popupMenu.add(menuItem);
//        popupmenu.model3duis.map.paste=Paste
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.map.paste"));
        popupMenu.add(menuItem);
//        popupmenu.model3duis.map.delete=Delete
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.map.delete"));
        popupMenu.add(menuItem);

        popupMenu.addSeparator();

//        popupmenu.model3duis.map.show=Show Map
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.map.show"));
        popupMenu.add(menuItem);
//        popupmenu.model3duis.map.hide=Hide Map
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.map.hide"));
        popupMenu.add(menuItem);

        popupMenu.addSeparator();

//        popupmenu.model3duis.map.move_to_top=Move To Top
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.map.move_to_top"));
        popupMenu.add(menuItem);
//        popupmenu.model3duis.map.move_to_bottom=Move To Bottom
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.map.move_to_bottom"));
        popupMenu.add(menuItem);
//        popupmenu.model3duis.map.move_up=Move Up
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.map.move_up"));
        popupMenu.add(menuItem);
//        popupmenu.model3duis.map.move_down=Move Down
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.map.move_down"));
        popupMenu.add(menuItem);

        popupMenu.addSeparator();

//        popupmenu.model3duis.map.clear_all=Clear All
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.map.clear_all"));
        popupMenu.add(menuItem);

        popupMenu.addSeparator();

//        popupmenu.model3duis.map.sava_as=Save As...
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.map.sava_as"));
        popupMenu.add(menuItem);

        return popupMenu;
    }


    public static JPopupMenu createDefaultPopupMenuForLayerNode(){
        ResourceBundle resourceBundle=ResourceBundle.getBundle("uiapi_resource", Locale.getDefault());

        JPopupMenu popupMenu = new JPopupMenu();
        JMenuItem menuItem = null;

//
//        popupmenu.model3duis.layer.rename=Rename
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.layer.rename"));
        popupMenu.add(menuItem);
        popupMenu.addSeparator();
//        popupmenu.model3duis.layer.copy=Copy
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.layer.copy"));
        popupMenu.add(menuItem);
//        popupmenu.model3duis.layer.paste=Paste
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.layer.paste"));
        popupMenu.add(menuItem);
//        popupmenu.model3duis.layer.delete=Delete
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.layer.delete"));
        popupMenu.add(menuItem);
        popupMenu.addSeparator();
//        popupmenu.model3duis.layer.show=SHow Layer
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.layer.show"));
        popupMenu.add(menuItem);
//        popupmenu.model3duis.layer.hide=Hide
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.layer.hide"));
        popupMenu.add(menuItem);
        popupMenu.addSeparator();
//        popupmenu.model3duis.layer.move_to_top=Move To Top
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.layer.move_to_top"));
        popupMenu.add(menuItem);
//        popupmenu.model3duis.layer.move_to_bottom=Move To Bottom
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.layer.move_to_bottom"));
        popupMenu.add(menuItem);
//        popupmenu.model3duis.layer.move_up=Move Up
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.layer.move_up"));
        popupMenu.add(menuItem);
//        popupmenu.model3duis.layer.move_down=Move Down
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.layer.move_down"));
        popupMenu.add(menuItem);
        popupMenu.addSeparator();
//        popupmenu.model3duis.layer.clear_all=Clear All
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.layer.clear_all"));
        popupMenu.add(menuItem);
        popupMenu.addSeparator();
//        popupmenu.model3duis.layer.attribute_structure=Attribute Structure...
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.layer.attribute_structure"));
        popupMenu.add(menuItem);
        popupMenu.addSeparator();
//        popupmenu.model3duis.layer.save_as=Save As...
        menuItem = new JMenuItem(resourceBundle.getString("popupmenu.model3d.layer.save_as"));
        popupMenu.add(menuItem);

        return popupMenu;
    }
}
